#!/bin/bash

# 删除Java安装目录
sudo rm -rf /usr/local/jdk1.8.0_371

# 删除Java相关环境变量
sudo sed -i '/Java environment variables/d' /etc/profile
sudo sed -i '/JAVA_HOME/d' /etc/profile
sudo sed -i '/JRE_HOME/d' /etc/profile
sudo sed -i '/CLASSPATH/d' /etc/profile
sudo sed -i '/PATH.*\/jdk1.8.0_371\/bin/d' /etc/profile

# 重新加载配置文件
source /etc/profile

# 检查Java卸载是否成功
if [ -z "$(command -v java)" ]; then
    echo "Java has been uninstalled successfully."
else
    echo "Failed to uninstall Java."
fi